package core;

import core.dashboard.Dashboard;
import core.helpers.ActionBuilderHelper;
import core.helpers.BrowserMobHelper;
import core.helpers.CSVHelper;
import core.helpers.ConfiguratorHelper;
import core.helpers.DBHelper;
import core.helpers.DateHelper;
import core.helpers.ExcelHelper;
import core.helpers.FileHelper;
import core.helpers.HarHelper;
import core.helpers.HttpHelper;
import core.helpers.JavaScriptHelper;
import core.helpers.LoggerHelper;
import core.helpers.MailHelper;
import core.helpers.MobDriverHelper;
import core.helpers.PropertyLoaderHelper;
import core.helpers.RandomizerHelper;
import core.helpers.RobotHelper;
import core.helpers.ScreenLoggerHelper;
import core.helpers.StringHelper;
import core.helpers.TestHelper;
import core.helpers.ThreadHelper;
import core.helpers.WebDriverHelper;
import core.helpers.WriterHelper;
import core.helpers.XmlRpcHelper;

/**
 * The main class
 * There is no emotion, there is peace. There is no ignorance, there is knowledge. There is no passion, there is
 * serenity. There is no death, there is the Force. (The Jedi Code)
 */
public class Pilot
{
	// Project configuration
	protected static Config config;
	public static String TEST_SCREENSHOT_FILENAME;
	public static String TEST_SCREENSHOT_PATH;

	// Helpers
	protected static WebDriverHelper webDriver;
	protected static MobDriverHelper mobDriver;
	protected static LoggerHelper logger;
	protected static ExcelHelper excel;
	private ScreenLoggerHelper screenLogger;
	private DBHelper db;
	private XmlRpcHelper xmlRpc;
	private ActionBuilderHelper actionBuilder;
	private DateHelper dateHelper;
	private StringHelper stringHelper;
	private BrowserMobHelper browserMobHelper;
	private HarHelper harHelper;
	private HttpHelper httpHelper;
	private FileHelper fileHelper;
	private JavaScriptHelper javaScriptHelper;
	private TestHelper testHelper;
	private RandomizerHelper randomizer;
	private RobotHelper robot;
	private ThreadHelper thread;
	private MailHelper mail;
	private ConfiguratorHelper configuratorHelper;
	private WriterHelper writerHelper;

	// Data Models
	protected static Dashboard dashboard;

	public Pilot()
	{
	}

	public boolean init(String p_os, String p_platform, String p_site, String p_browserName)
	{
		this.dashboard()
				.setServerType("saucelabs")
				.setOS(p_os)
				.setPlatform(p_platform)
				.setSiteUrl("")
				.setProxy("def")
				.setBrowserName(p_browserName)
				.setBrowserVersion("def")
				.setSaucelabsUsername("babar_igor")
				.setSaucelabsKey("3b1b1acd-fcd4-4d89-a4b1-7931cfc77c73")
				.setSiteURL(p_site);

		dashboard().print();

		if (dashboard().getPlatform().equals(config().PLATFORM_WEB))
		{
			return driver().runLocalBrowser(dashboard().getBrowserName(), dashboard().getProxy());
		}
		else if (dashboard().getPlatform().equals(config().PLATFORM_MOBILE))

		{
			return md().runLocalBrowser();
		}

		return false;
	}

	public Config config()
	{
		if (config == null)
		{
			try
			{
				config = new Config(this);
			}
			catch (Exception p_ex)
			{

			}
		}

		return config;
	}

	public DateHelper date()
	{
		if (dateHelper == null)
		{
			dateHelper = new DateHelper(this);
		}
		return dateHelper;
	}

	public StringHelper string()
	{
		if (stringHelper == null)
		{
			stringHelper = new StringHelper(this);
		}

		return stringHelper;
	}

	public DBHelper db()
	{
		if (db == null)
		{
			db = new DBHelper(this);
		}

		return db;
	}

	public WebDriverHelper driver()
	{
		if (webDriver == null)
		{
			webDriver = new WebDriverHelper(this);
		}

		return webDriver;
	}

	public MobDriverHelper md()
	{
		if (mobDriver == null)
		{
			mobDriver = new MobDriverHelper(this);
		}

		return mobDriver;
	}

	public XmlRpcHelper xmlRpc()
	{
		if (xmlRpc == null)
		{
			xmlRpc = new XmlRpcHelper(this);
		}

		return xmlRpc;
	}

	public ActionBuilderHelper actionBuilder()
	{
		if (actionBuilder == null)
		{
			actionBuilder = new ActionBuilderHelper(this);
		}

		return actionBuilder;
	}

	// public ScreenLoggerHelper screenLogger()
	// {
	// if (screenLogger == null)
	// {
	// screenLogger = new ScreenLoggerHelper(this);
	// }
	//
	// return screenLogger;
	// }

	public BrowserMobHelper browserMob()
	{
		if (browserMobHelper == null)
		{
			browserMobHelper = new BrowserMobHelper(this);
		}

		return browserMobHelper;
	}

	public HarHelper har()
	{
		if (harHelper == null)
		{
			harHelper = new HarHelper(this);
		}

		return harHelper;
	}

	public HttpHelper http()
	{
		if (httpHelper == null)
		{
			httpHelper = new HttpHelper(this);
		}

		return httpHelper;
	}

	public FileHelper file()
	{
		if (fileHelper == null)
		{
			fileHelper = new FileHelper(this);
		}

		return fileHelper;
	}

	public TestHelper tester()
	{
		if (testHelper == null)
		{
			testHelper = new TestHelper(this);
		}

		return testHelper;
	}

	public JavaScriptHelper js()
	{
		if (javaScriptHelper == null)
		{
			javaScriptHelper = new JavaScriptHelper(this);
		}
		return javaScriptHelper;
	}

	public RobotHelper robot()
	{
		if (robot == null)
		{
			robot = new RobotHelper(this);
		}
		return robot;
	}

	public ThreadHelper thread()
	{
		if (thread == null)
		{
			thread = new ThreadHelper(this);
		}
		return thread;
	}

	public Dashboard dashboard()
	{
		if (dashboard == null)
		{
			dashboard = new Dashboard(this);
		}

		return dashboard;
	}

	public String getCallerPath(int p_depth)
	{
		String callerPath = Thread.currentThread().getStackTrace()[p_depth].getClassName();

		return callerPath;
	}

	public LoggerHelper log()
	{
		if (logger == null)
		{
			logger = new LoggerHelper(this);
		}

		return logger;
	}

	public PropertyLoaderHelper propertyLoader(String p_file)
	{
		return new PropertyLoaderHelper(this, p_file);
	}

	public RandomizerHelper randomizer()
	{
		if (randomizer == null)
		{
			randomizer = new RandomizerHelper(this);
		}

		return randomizer;
	}

	public CSVHelper csv()
	{
		return new CSVHelper(this);
	}

	public ExcelHelper excel()
	{
		if (excel == null)
		{
			excel = new ExcelHelper(this);
		}
		return excel;
	}

	public MailHelper mail()
	{
		if (mail == null)
		{
			mail = new MailHelper(this);
		}

		return mail;
	}

	public ConfiguratorHelper configurator()
	{
		if (configuratorHelper == null)
		{
			configuratorHelper = new ConfiguratorHelper(this);
		}

		return configuratorHelper;
	}

	public WriterHelper writer()
	{
		if (writerHelper == null)
		{
			writerHelper = new WriterHelper(this);
		}

		return writerHelper;
	}

}